package com.example.bookstore;

import android.app.AlertDialog;
import android.icu.text.Collator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.ViewHolder>{
    private List<Order> orderList ;

    public OrderAdapter(List<Order> orderList) {
        this.orderList = orderList;
    }


    @NonNull
    @Override
    public OrderAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_list,parent,false);
        OrderAdapter.ViewHolder holder = new OrderAdapter.ViewHolder(view);
//        holder.view.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                int position = holder.getAdapterPosition();
//                AlertDialog.Builder builder=new AlertDialog.Builder(v.getContext());
//                View view1=LayoutInflater.from(v.getContext()).inflate(R.layout.dialog,null);
//                builder.setView(view1);
//                builder.setTitle("订单详情");
//                RecyclerView recyclerView=(RecyclerView)view1.findViewById(R.id.order_book_list);
//
//                builder.show();
//            }
//        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull OrderAdapter.ViewHolder holder, int position) {
        Order order = orderList.get(position);
       holder.id.setText(Integer.toString(order.getId()));
       holder.price.setText(Double.toString(order.getPrice()));
       holder.size.setText(Integer.toString(order.getSize()));

    }

    @Override
    public int getItemCount() {
        return orderList.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        View view;
        private TextView id;
        private TextView price;
        private TextView size;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            view = itemView;
            id = (TextView)itemView.findViewById(R.id.order_id);
            price = (TextView)itemView.findViewById(R.id.total_price);
            size =(TextView)itemView.findViewById(R.id.num);

        }
    }
}
